import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:theme_page/pages/donggudi_theme/ticailist.dart';


const bool PlatMode = true;

void platMain(List<String> args) {
  if (args.length != 2) {
    print("Error: Expected exactly 2 arguments, but got ${args.length}");
    return;
  }
  try {
    var url = args[0];
    Map<String, dynamic> paraJson = jsonDecode(args[1]);
    Map<String, String> para = paraJson.map((key, value) => MapEntry(key, value.toString()));
    runApp(MyApp(initialUrl: url, initialParams: para));
  } catch (e) {
  }
}

void main(List<String> args) {
  if (PlatMode) {
    platMain(args);
    return;
  }
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    systemNavigationBarColor: Colors.transparent,
    statusBarIconBrightness: Brightness.light, // 将状态栏图标颜色设置为白色
  ));
  runApp(MyApp());

}

class MyApp extends StatelessWidget {
  final String? initialUrl;
  final Map<String, String>? initialParams;

  MyApp({this.initialUrl, this.initialParams});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(375, 812),
      minTextAdapt: true,
      builder: (context, child) {
        return AnnotatedRegion<SystemUiOverlayStyle>(
          value: SystemUiOverlayStyle(
            statusBarColor: Colors.transparent,
            systemNavigationBarColor: Colors.white,
            statusBarIconBrightness: Brightness.light, // 确保状态栏图标为白色
            systemNavigationBarIconBrightness: Brightness.dark, // 底部导航栏图标颜色为黑色
          ),
          child: MaterialApp(
            debugShowCheckedModeBanner: false,
            title: 'Theme Page',
            theme: ThemeData(
              primarySwatch: Colors.blue,
              scaffoldBackgroundColor: Colors.white,
              appBarTheme: AppBarTheme(
                color: Colors.transparent,
                elevation: 0,
                iconTheme: IconThemeData(color: Colors.white),
              ),
            ),
            localizationsDelegates: [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],
            supportedLocales: [
              const Locale('en', ''),
              const Locale('zh', ''),
            ],
            home:
            (initialUrl == '/bankuai/ticai' || initialUrl == '/ticai/detail')
                ? null
                : TicaiList(parameters: initialParams ?? {'page': '1', 'pageCount': '10', 'day': '20241029'}),

          ),
        );
      },
    );
  }
}
